﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ARR.Entities;
using ARR.DataModel.Repositories;
using DDF.Entity;

namespace ARR.Services.Domain
{
    public static class InventoriesDomain
    {
        public static List<Article> GetNewArticles(int rangeReviewId)
        {
            var articles = TempInventoriesRepository.SelectNewArticles(rangeReviewId).ConvertAll<Article>(row => new Article(row));

            var categories = CategoriesDomain.GetAll();

            articles.ForEach(x => 
                {
                    x.CategoryCode = x.GetRow().CategoryCode;
                    x.Category = categories.SingleOrDefault(c => c.Code == x.CategoryCode);

                    if(x.Category != null)
                    {
                        x.CategoryId = x.Category.Id;
                    }
                });

            return articles;
        }

        public static void TempInvetoriesUpdateIds(int rangeReviewId)
        {
            TempInventoriesRepository.UpdateIds(rangeReviewId);
        }
    }
}
